package com.dhcc.wb.articleday;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.json.JSONObject;

import com.dhcc.bussiness.page.PageBean;
import com.dhcc.wb.articleliushui.ArticleDetailsModel;
import com.dhcc.wb.articleliushui.ArticleGzhModel;
import com.dhcc.wb.articleliushui.ArticleLiushuiDao;
import com.dhcc.wb.articleliushui.ArticleShowModel;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class ArticleAction extends ActionSupport {
	private static final long serialVersionUID = 1L;
	private static Logger logger = Logger.getLogger(ActionSupport.class);
	
	private Integer currentPage;
	private Integer currentCount = 10;
	private PageBean<ArticleShowModel> pageBean = new PageBean<ArticleShowModel>();
	
	private String ids;//
    private String ref_date;//获取数据日期
    private String msgid;//
    
    private ArticleLiushuiDao liushuidao = new ArticleLiushuiDao();
    private String result;//
    
    private ArticleDayService dayservice = new ArticleDayService();
    private ArticledayDao daydao = new ArticledayDao();
    
	
    //文章列表页面
	public String article() throws Exception {
		// TODO Auto-generated method stub
		HttpServletRequest request = ServletActionContext.getRequest();
		int currentPage = Integer.parseInt(request.getParameter("currentPage")==null?"1":request.getParameter("currentPage"));//规定是第一页
		String title = request.getParameter("title");
		pageBean = dayservice.findArticleShowServiceByPage(currentPage, currentCount, title);
		ActionContext.getContext().getSession().put("pageBean", pageBean);
		return SUCCESS;
	}
	//文章管理 二级页面 哪些公众号
	public String articlegzh() throws Exception {
		// TODO Auto-generated method stub
		HttpServletRequest request = ServletActionContext.getRequest();
		String title = request.getParameter("title");
		List<ArticleGzhModel> articleGzhlist = daydao.findArticleDayService(title);
		ActionContext.getContext().getSession().put("articleGzhlist", articleGzhlist);
		ActionContext.getContext().getSession().put("title", title);
		return SUCCESS;
	}
	//文章管理 二级页面 哪些公众号
	public String articlegzhsanji() throws Exception {
		// TODO Auto-generated method stub
		HttpServletRequest request = ServletActionContext.getRequest();
		String title = request.getParameter("title");
		String gzhname = request.getParameter("gzhname");
		
		
		
		
		List<ArticleGzhModel> articleGzhlist = daydao.findArticleDayService(title,gzhname);
		ActionContext.getContext().getSession().put("articleGzhsanjilist", articleGzhlist);
		ActionContext.getContext().getSession().put("gzhname", gzhname);
		ActionContext.getContext().getSession().put("title", title);
		return SUCCESS;
	}
	
	//获取每篇文章的统计阅读量
	public String findMax() {
		HttpServletRequest request = ServletActionContext.getRequest();
		String msgid = request.getParameter("msgid");
		ArticleDetailsModel detail = liushuidao.queryArticleMax_result(msgid);
		JSONObject jsons = new JSONObject();
		jsons.put("result",detail.getInt_page_read_count());
		result = jsons.toString();
		return SUCCESS;
	}


	public Integer getCurrentPage() {
		return currentPage;
	}



	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
	}



	public Integer getCurrentCount() {
		return currentCount;
	}



	public void setCurrentCount(Integer currentCount) {
		this.currentCount = currentCount;
	}



	public String getIds() {
		return ids;
	}



	public void setIds(String ids) {
		this.ids = ids;
	}



	public String getRef_date() {
		return ref_date;
	}



	public void setRef_date(String ref_date) {
		this.ref_date = ref_date;
	}



	public String getMsgid() {
		return msgid;
	}



	public void setMsgid(String msgid) {
		this.msgid = msgid;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}



	

	
}
